// pages/zhuce/zhuce.js
Page({
  data: {

  },
  submit(e){
    console.log(e)
    let username=e.detail.value.username
    let password=e.detail.value.password
    let password2=e.detail.value.password2
    if(username.length==0){
      wx.showToast({
        title: '账号不可为空',
        icon:'error'
      })
      return
    }
    if(password.length==0){
      wx.showToast({
        title: '密码不可为空',
        icon:'error'
      })
      return
    }
    if(password!=password2){
      wx.showToast({
        title: '密码不同',
        icon:'error'
      })
      return
    }
    wx.request({
      url: 'http://127.0.0.1:8080/user',
      method:'POST',
      data:{
        name:username,
        password:password
      },
      success:res=>{
        if(res.statusCode==200){
          wx.showToast({
            title: '注册成功',
            icon:'success'
          })
          wx.navigateTo({
            url: '/pages/login/login',
          })
          return
        }
        if (res.statusCode==500) {
          wx.showToast({
            title: '注册失败',
            icon:'error'
          })
        }
      }
    })

  }
})